package com.spddr.pmos.cxf.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.spddr.pmos.cxf.JaxrsCompany;
import com.spddr.pmos.jpa.Company;
import com.spddr.pmos.jpa.Customer;
import com.spddr.pmos.jpa.Plant;
import com.spddr.pmos.repos.CompanyRepos;
import com.spddr.pmos.repos.CustomerRepos;
import com.spddr.pmos.repos.PlantRepos;

@Service
public class JaxrsCompanyImpl extends AbstractJaxrsObjectImpl<Company> implements JaxrsCompany {
	@Autowired
	private CompanyRepos repository;
	@Autowired
	private PlantRepos plantRepos;
	@Autowired
	private CustomerRepos customerRepos;

	@Override
	public JpaRepository<Company, Long> getRepository() {
		return repository;
	}

	@Override
	public List<Company> children(long id) {
		return repository.findByParentId(id);
	}

	@Override
	public List<Plant> plants(long id) {
		return plantRepos.findByCompanyId(id);
	}

	@Override
	public List<Customer> customers(long id) {
		return customerRepos.findAll();
	}
}
